﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WF.Web.Pages.UserControl
{
    public partial class UCPager : System.Web.UI.UserControl
    {
        private String _PagedControlID;

        public String PagedControlID
        {
            get { return _PagedControlID; }
            set { _PagedControlID = value; }
        }

        public Int32 PageSize
        {
            get { return this.dpUCList.PageSize; }
            set { this.dpUCList.PageSize = value; }
        }

        public int PageNo
        {
            get { return (this.dpUCList.StartRowIndex + this.dpUCList.PageSize) / this.dpUCList.PageSize; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Page_Init(object sender, EventArgs e)
        {
            this.dpUCList.PagedControlID = _PagedControlID;
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.dpUCList.PageSize = PageSize;
                this.txtToPage.Text = (this.dpUCList.StartRowIndex + 1).ToString();
            }
            this.lblTotalNum.Text = System.Math.Ceiling((this.dpUCList.TotalRowCount * 0.1) / (this.dpUCList.PageSize * 0.1)).ToString();
            if (this.lblTotalNum.Text == "0")
            {
                this.lblNowPageNum.Text = "0";
            }
            else
            {
                this.lblNowPageNum.Text = ((this.dpUCList.StartRowIndex + this.dpUCList.PageSize) / this.dpUCList.PageSize).ToString();
            }
        }

        //点Go时。

        protected void imgbtnGo_Click(object sender, ImageClickEventArgs e)
        {
            if (int.Parse(this.txtToPage.Text) <= int.Parse(this.lblTotalNum.Text))
            {
                this.dpUCList.SetPageProperties((int.Parse(this.txtToPage.Text) - 1) * this.dpUCList.PageSize, this.dpUCList.PageSize, false);
            }
        }

        //每页记录数改变时。

        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.dpUCList.PageSize = int.Parse(drpPageSize.SelectedItem.Value);
            this.dpUCList.SetPageProperties(0, this.dpUCList.PageSize, false);
        }
    }
}